const bucket = new WeakMap() // 改造为{object1:{name:Set(fn,fn),age:[fn,fn]},object2:{name:Set(fn,fn),age:[fn,fn]}}
let activeEffect = null
function isObject(obj) {
  return typeof obj === 'object' && obj !== null
}
function trigger(target, key) {
  if (!isObject(target)) return
  const depMap = bucket.get(target)
  if (!depMap) return
  depSet = depMap.get(key)
  if (depSet) {
    depSet.forEach((fn) => fn())
  }
}
function effect(fn) {
  activeEffect = fn
  fn()
  activeEffect = null
}
function track(target, key) {
  if (!isObject(target)) return
  if (!activeEffect) return
  let depMap = bucket.get(target)
  if (!depMap) {
    depMap = new Map()
    bucket.set(target, depMap)
  }
  let depSet = depMap.get(key)
  if (!depSet) {
    depSet = new Set()
    depMap.set(key, depSet)
  }
  depSet.add(activeEffect)
}
function reactive(data) {
  if (!isObject(data)) return
  return new Proxy(data, {
    get(target, key) {
      track(target, key)
      return target[key]
    },
    set(target, key, value) {
      target[key] = value
      trigger(target, key)
      return true
    },
  })
}
